import { formatterZH } from './zh'

import { numberToFixed } from './numberToFixed'

export function toFixed(value, num = 2) {
  return isNaN(value) ? value : numberToFixed(+value, num)
}

export function toFixedTwo(value) {
  return toFixed(value, 2)
}

export function toSafeFloat(value, num = 2) {
  return isNaN(value) ? value : +numberToFixed(+value, num)
}

const formatter = {
  zh: formatterZH,
}

export function formatMoney(money, type) {
  if (!formatter[type]) throw new Error('az-money-formatter: Invalid or unexpected type')
  return formatter[type](money)
}
